$(function () {
  var number = 10;
  var page = 1;
  var total_a;
  var page_a;
  $("#previous").click(function () {
    $("tr > td").remove();
    if (page == 1) {
      alert("已经是第一页，请按下一页");
      return false;
    }
    page--;
    if (page_a < page) {
      alert("没有数据了");
      return false;
    }
    request(number, page);
  });

  $("#next").click(function () {
    $("tr > td").remove();
    page++;
    if (page_a < page) {
      alert("没有数据了");
      return false;
    }
    request(number, page);
  });
  request(number, page);

  function request(numebr, page) {
    $.ajax({
      type: "POST",
      url: "/student/selectStudent",
      async: false,
      data: {"number": number, "page": page},
      dataType: "json",
      success: function (data) {
        if (data == "" || data == null) {
          alert("服务器繁忙");
        }
        if (data.code == 200) {
          total_a = data.total;
          page_a = total_a / number;
          var html = "";
          var list = data.data;
          for (var i = 0; i < list.length; i++) {
            var student = list[i];
            html += "<tr>" +
                "<td>" + student.studentId + "</td>" +
                "<td>" + student.name + "</td>" +
                "<td>" + student.gender + "</td>" +
                "<td>" + student.age + "</td>" +
                "<td>" + student.grade + "</td>" +
                "<td>" + student.introduce + "</td>" +
                "<td><a  href='/student/selectAloneStudent?studentId="
                + student.studentId + "' class='code'  studentId='"
                + student.studentId + "'>编辑</a> <a href='/student/deleteStudent?studentId="+ student.studentId + "' class='code_a' studentId='"
                + student.studentId + "'>删除</a></td>" +
                "</tr>";
          }
          $("#table").append(html);
        } else {
          alert(data.msg);
        }
      }
    })
  }
  $("#modal").iziModal({
    title:"是否删除",
    headerColor:"#FF0000",
    iconColor:"#0084FF",
    width:200,
  });

  $(document).on('click', '.code_a', function (event) {
    event.preventDefault();
    $('#modal')
    .iziModal('open', event);
  })
  $("#button_b").click(function () {
    $('#modal').iziModal('close');
  })
  $("#button_a").click(function () {

  })


/*    $(".code").click(function () {
      var $id = $(this).attr("studentId");

      $.ajax({
        type: "POST",
        url: "/student/selectAloneStudent",
        async: false,
        data: {"studentId":$id},
        dataType: "json",
        success: function (data) {
          if (data == "" || data == null) {
            alert("服务器繁忙");
          }
          if (data.code == 200) {
            location.href = data.data;
          }else {
            alert(data.msg());
          }
        }
      })
    })*/

});